<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="200px">
        <el-menu :router="true" active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo"
          default-active="2" text-color="#fff" @open="handleOpen" @close="handleClose">
          <template v-for="item in menudata">
            <el-menu-item v-if="!item.children" :index="item.path">
              {{ item.label }}
            </el-menu-item>
            <el-sub-menu v-else :index="item.id">
              <template #title>
                <span>{{ item.label }}</span>
              </template>
              <el-menu-item v-for="sonItem in item.children" :index="sonItem.path">{{ sonItem.label }}</el-menu-item>
            </el-sub-menu>
          </template>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header>
          <div class="box">
            <h1>嗨购商城后台管理系统</h1>
            <p>Hi Shopping Mall's background management system</p>
            <button @click="fun"> 欢迎您：{{ username }} 退出
              <el-icon>
                <SwitchButton />
              </el-icon>
            </button>
          </div>
        </el-header>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from "vue-router";
import { reactive, ref } from 'vue'
import getMenus from "../../grants/menudata"
import getRoutes, { clearCurrentRoutes } from "../../grants/router"
import {
  ShoppingBag,
  Shop,
  Picture,
  Avatar,
  Postcard,
  DocumentAdd,
  Edit,
  ShoppingCart,
  Coordinate,
  List,
  UserFilled,
  SwitchButton
} from '@element-plus/icons-vue'
const menudata = reactive(getMenus());
getRoutes();


const $router = useRouter();

const handleOpen = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log(key, keyPath)
}

const username = ref(sessionStorage.getItem("username"))

const fun = () => {
  sessionStorage.clear()
  clearCurrentRoutes();//清除当前用户的路由配置；
  $router.push("/login")
}



</script>

<style scoped>
.common-layout {
  width: 100%;
  height: 100%;
}

.el-container {
  width: 100%;
  height: 100%;
}

.el-aside {
  width: 200px;
  height: 100%;
  background: rgba(82, 90, 100);
}

.el-header {
  width: 100%;
  height: 100px;
  padding: 0;
  background: cadetblue;
}

.box {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  background: url(../../assets/1.jpg)100%;
  font-weight: bolder;
}

.box button {
  position: fixed;
  right: 10px;
  top: 60px;
  background: rgb(2, 105, 105);
  border: none;
  border-radius: 5px;
  color: #fff;
  text-align: center;
}
</style>